package com.lagou.sort;

import org.apache.hadoop.io.*;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class Reduce extends Reducer<IntWritable, IntWritable,IntWritable, IntWritable> {
    IntWritable lineNum = new IntWritable(1);


    @Override
    protected void reduce(IntWritable key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException {

        for (IntWritable val : values){
            context.write(lineNum, key);      // key 为1,value为map中的key
            lineNum = new IntWritable(lineNum.get()+1);    // 简单自增
        }
    }
}
